package com.william.killian.trivia;

import java.io.File;
import java.util.ArrayList;

import android.app.ListActivity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.william.killian.trivia.model.HighScoreEntry;
import com.william.killian.trivia.model.HighScoreList;

public class HighScoreViewer extends ListActivity
{
    ArrayList<HighScoreEntry> entries;
    
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate (savedInstanceState);
        setTheme (android.R.style.Theme_Light);
        
        Bundle extras = getIntent ().getExtras ();
        if (extras != null)
        {
            LayoutInflater li = getLayoutInflater ();
            TextView header = (TextView)li.inflate (android.R.layout.simple_list_item_1, null);
            header.setText (R.string.text_score_header);
            header.setTypeface (header.getTypeface (), Typeface.BOLD);
            View footer = li.inflate (R.layout.scores_footer, null);
            
            getListView ().addHeaderView (header);
            getListView ().addFooterView (footer);
            
            File hs = (File)extras.getSerializable ("highscore");
            HighScoreList scores = HighScoreList.Load (hs);
            entries = scores.getScores ();
            setListAdapter (new ArrayAdapter <HighScoreEntry> (this, android.R.layout.simple_list_item_1, entries));
        }
    }
    
    public void close (View v)
    {
        finish();
    }
}
